// 6. 惩罚计时模块 (无改动)
module penalty_timer(
    input clk,
    input rst_n,
    input game_reset,
    input input_error,
    output reg [15:0] penalty_time_100ms  // 惩罚时间，单位0.1秒
);

    reg input_error_d1;
    wire input_error_posedge;

    // 检测input_error的上升沿，确保每次错误只计数一次
    always @(posedge clk or negedge rst_n) 
    begin
        if (!rst_n) begin
            input_error_d1 <= 0;
        end 
        else begin
            input_error_d1 <= input_error;
        end
    end

    assign input_error_posedge = input_error & (~input_error_d1);

    always @(posedge clk or negedge rst_n) 
    begin
        if (!rst_n) 
        begin
            penalty_time_100ms <= 0;
        end 
        else if (game_reset) begin
            penalty_time_100ms <= 0;
        end 
        else if (input_error_posedge) 
        begin
            penalty_time_100ms <= penalty_time_100ms + 1;  // 每次错误增加0.1秒
        end
    end
endmodule
